package com.itheima.controller;

import com.itheima.domain.Book;
import com.itheima.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 陆小根
 * date: 2022/05/04
 * Description:
 */
@RestController
@RequestMapping("/books")
public class BookController {

  @Autowired
  private BookService bookService;

  @PostMapping
  public boolean save(@RequestBody Book book) {
    return bookService.save(book);
  }

  @DeleteMapping("{id}")
  public boolean delete(@PathVariable("id") Integer id) {
    return bookService.delete(id);
  }

  @PutMapping
  public boolean update(@RequestBody Book book) {
    return bookService.update(book);
  }

  @GetMapping("{id}")
  public Book getById(@PathVariable("id") Integer id) {
    return bookService.getById(id);
  }

  @GetMapping
  public List<Book> getAll() {
    return bookService.getAll();
  }

}
